import React from 'react';
import { Router, hashHistory } from 'react-router';
import userDatauserData from 'js/core/userData';

const routes = [
	{
		path: '/login',
		getComponent: (nextState, cb) => {
			require.ensure([], (require) => {
				cb(null, require('views/login/login').default);
			}, 'login');
		},
	},
	{
		path: '/register',
		getComponent: (nextState, cb) => {
			require.ensure([], (require) => {
				cb(null, require('views/register/register').default);
			}, 'register');
		},
	},
	{
		path: '/forget',
		getComponent: (nextState, cb) => {
			require.ensure([], (require) => {
				cb(null, require('views/forget/forget').default);
			}, 'forget');
		},
	},
	{
		path: '/pic',
		getComponent: (nextState, cb) => {
			require.ensure([], (require) => {
				cb(null, require('views/pic').default);
			}, 'pic');
		},
	},
	// 首页
	{
		path: '/',
		getComponent: (nextState, cb) => {
			require.ensure([], (require) => {
				cb(null, require('views/main/main').default);
			}, 'main');
		},
		onEnter: (nextState, replace) => {
			let user = userData.get();
			if (!user.token) {
				replace({ pathname: '/login' });
			}
		},
		onChange: (prevState, nextState, replace) => {
			let user = userData.get();
			if (!user.token) {
				replace({ pathname: '/login' });
			}
		},
		indexRoute: {
			getComponent: (nextState, cb) => {
				require.ensure([], (require) => {
					cb(null, require('views/home/home').default);
				}, 'home1');
			},
		},
		childRoutes: [
			{
				path: '/home',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/home/home').default);
					}, 'home');
				}
			},
			{
				path: '/my',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/page/my/my').default);
					}, 'my');
				}
			},
			// 设置
			{
				path: '/set',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/page/set/set').default);
					}, 'set');
				},
			},
			{
				path: '/device',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/page/set/device/device').default);
					}, 'device');
				},
			},
			{
				path: '/active',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/page/set/active/active').default);
					}, 'active');
				},
			},
			{
				path: '/addDevice',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/page/set/addDevice/add').default);
					}, 'addDevice');
				},
			},
			{
				path: '/addActive',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/page/set/addActive/add').default);
					}, 'addActive');
				},
			},

			{
				path: '/shopTour',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/page/set/shopTour/shopTour').default);
					}, 'shopTour');
				},
			},
			{
				path: '/totalFlow',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/totalFlow/totalFlow').default);
					}, 'totalFlow');
				},
			},
			{
				path: '/brandFlow',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/totalFlow/brandFlow').default);
					}, 'brandFlow');
				},
			},
			{
				path: '/regionFlow',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/totalFlow/regionFlow').default);
					}, 'regionFlow');
				},
			},
			{
				path: '/multiStoreFlow',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/flow/multiStoreFlow').default);
					}, 'multiStoreFlow');
				},
			},
			{
				path: '/flowFace',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/flowFace/flowFace').default);
					}, 'flowFace');
				},
			},
			{
				path: '/flow(/:id/:type)',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/flow/flow').default);
					}, 'flow');
				},
			},
			{
				path: '/find',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/page/find/find').default);
					}, 'find');
				},
			},
			{
				path: '/deviceMgr',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/deviceMgr/deviceMgr').default);
					}, 'deviceMgr');
				},
			},
			{
				path: '/imgRecord',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/imgRecord/imgRecord').default);
					}, 'imgRecord');
				},
			},
			{
				path: '/storeRecord',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/storeRecord/storeRecord').default);
					}, 'storeRecord');
				},
			},
			{
				path: '/storeAnalysis',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/storeAnalysis/storeAnalysis').default);
					}, 'storeAnalysis');
				},
			},
			{
				path: '/handleList',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/handleList/handleList').default);
					}, 'handleList');
				},
			},
			{
				path: '/addHandleList',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/handleList/addHandleList').default);
					}, 'addHandleList');
				},
			},
			{
				path: '/shopSearch',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/shopSearch/shopSearch').default);
					}, 'shopSearch');
				},
			},
			{
				path: '/selectDataTypeId',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/selectDataTypeId/selectDataTypeId').default);
					}, 'selectDataTypeId');
				},
			},
			{
				path: '/zoneFlow',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/flow/zoneFlow').default);
					}, 'zoneFlow');
				},
			},
			{
				path: '/eas',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/eas/eas').default);
					}, 'eas');
				},
			},
			{
				path: '/monitoring',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/monitoring/monitoring').default);
					}, 'monitoring');
				},
			},
			{
				path: '/monitoringMatch',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/monitoringMatch/monitoringMatch').default);
					}, 'monitoringMatch');
				},
			}, {
				path: '/singleStoreFlow',
				getComponent: (nextState, cb) => {
					require.ensure([], (require) => {
						cb(null, require('views/flow/singleStoreFlow').default);
					}, 'singleStoreFlow');
				},
			}
		]
	},

];

class RouterConfig extends React.Component {
	render() {
		return <Router history={hashHistory} routes={routes} />;
	}
}

export default RouterConfig;
